using System.Web.UI.WebControls;
using ExtendedMvc.Common.Diagnostics;

namespace ExtendedMvc.Elements {
	public class ImageLink : ImageLinkBase<ImageLink> {
		public ImageLink(string source, string link, string id = null) : base(source, link, id) { }
	}

	public class ImageLinkBase<T> : LinkBase<T> where T : ImageLinkBase<T> {
		private const string imageIdSuffix = "_Image";
		private Image _image;

		public ImageLinkBase(string source, string link, string id = null)
			: base(string.Empty, link, id) {
			_image = new Image(source, id == null ? null : id + imageIdSuffix);
		}

		public virtual T Source(string value) {
			Check.Argument.IsNotNullOrEmpty(value, "Source");
			_image.Source(value);
			return (T)this;
		}

		#region Size
		public virtual T Size(int width, int height) { _image.Size(width, height); return (T)this; }

		public virtual T Size(string width, string height) { _image.Size(width, height); return (T)this; }

		public virtual T Size(Unit width, Unit height) { _image.Size(width, height); return (T)this; }
		#endregion

		#region Width
		public virtual T Width(int width) { _image.Width(width); return (T)this; }

		public virtual T Width(string width) { _image.Width(width); return (T)this; }

		public virtual T Width(Unit width) { _image.Width(width); return (T)this; }
		#endregion

		#region Height
		public virtual T Height(int height) { _image.Height(height); return (T)this; }

		public virtual T Height(string height) { _image.Height(height); return (T)this; }

		public virtual T Height(Unit height) { _image.Height(height); return (T)this; }
		#endregion

		protected override void SetId() {
			base.SetId();
			_image.Id(id == null ? null : id + imageIdSuffix);
		}

		protected override void SetContent() {
			Builder.InnerHtml = _image.ToString();
		}
	}
}